from re import S
from manimlib import *


# 75cfb8
# bbdfc8
# f0e5d8
# ffc478
class p1(Scene):
    def construct(self):
        self.camera.frame.scale(1.4)
        # self.add(NumberPlane())
        width = 9
        height = 8
        b, c, d, a = [-width / 2, height / 2, 0], [width / 2, height / 2, 0], [width / 2, -height / 2, 0], [-width / 2,
                                                                                                            -height / 2,
                                                                                                            0]
        abcd = Polygon(a, b, c, d)
        b8 = Brace(abcd, LEFT).set_color(BLACK)
        self.add(b8, abcd,
                 Tex('A').next_to(a, DL),
                 Tex('B').next_to(b, UL),
                 Tex('C').next_to(c, UR),
                 Tex('D').next_to(d, DR),
                 Tex('8').next_to(b8, LEFT)
                 )
        # circle
        circle_3 = Circle().scale(2).next_to(b, DR, buff=0)
        r = circle_3.get_width() / 2
        circle_4 = Circle()
        circle_4.add_updater(lambda m: m.become(Circle().set_width(10 - circle_3.get_width()).next_to(d, UL, buff=0)))
        self.add(circle_3, circle_4)
        # line
        p = np.array([4 * r / 5, -3 * r / 5, 0]) + circle_3.get_center()
        e = p + np.array([0, 6 * r / 5, 0])
        f = e + np.array([0, -6, 0])
        self.add(
            Line(e, f),
            Tex('E').next_to(e),
            Tex('F').next_to(f),
            Tex('P').next_to(p)
        )
        # animate
        self.wait()


class p2(Scene):
    def construct(self):
        self.camera.frame.scale(1.4)
        width = 9
        height = 8
        b, c, d, a = [-width / 2, height / 2, 0], [width / 2, height / 2, 0], [width / 2, -height / 2, 0], [-width / 2,
                                                                                                            -height / 2,
                                                                                                            0]
        abcd = Polygon(a, b, c, d)
        b8 = Brace(abcd, LEFT).set_color(BLACK)
        self.add(b8, abcd,
                 Tex('A').next_to(a, DL),
                 Tex('B').next_to(b, UL),
                 Tex('C').next_to(c, UR),
                 Tex('D').next_to(d, DR),
                 Tex('8').next_to(b8, LEFT),

                 )
        # circle
        circle_3 = Circle().scale(2).next_to(b, DR, buff=0)
        r = circle_3.get_width() / 2
        circle_4 = Circle().set_width(10 - circle_3.get_width()).next_to(d, UL, buff=0)
        self.add(circle_3, circle_4)
        # line
        p = np.array([4 * r / 5, -3 * r / 5, 0]) + circle_3.get_center()
        e = p + np.array([0, 6 * r / 5, 0])
        f = e + np.array([0, -6, 0])
        o1, o2 = circle_3.get_center(), circle_4.get_center()
        m, n = (e + p) / 2, (f + p) / 2
        line_x, line_y = Line(o1, o1 + UP * r), Line(o2, o2 + DOWN * (5 - r))
        self.add(line_x, line_y,
                 Line(e, f),
                 Tex('E').next_to(e),
                 Tex('F').next_to(f),
                 Tex('P').next_to(p),
                 Tex('M').next_to(m, UL),
                 Tex('N').next_to(n, UL),
                 Tex('x').next_to(line_x),
                 Tex('y').next_to(line_y),
                 Line(o1, o1 + RIGHT * r),
                 Line(o2, o2 + LEFT * (5 - r)),
                 Tex('O').next_to(o1, DL),
                 Tex('O^\prime').next_to(o2, UR)
                 )
        # animate
        self.wait()


class p3(Scene):
    def construct(self):
        self.camera.frame.scale(1.2)
        width = 9
        height = 8
        b, c, d, a = [-width / 2, height / 2, 0], [width / 2, height / 2, 0], [width / 2, -height / 2, 0], [-width / 2,
                                                                                                            -height / 2,
                                                                                                            0]
        abcd = Polygon(a, b, c, d)
        b8 = Brace(abcd, LEFT).set_color(BLACK)
        self.add(b8, abcd,
                 Tex('A').next_to(a, DL),
                 Tex('B').next_to(b, UL),
                 Tex('C').next_to(c, UR),
                 Tex('D').next_to(d, DR),
                 Tex('8').next_to(b8, LEFT)
                 )
        # circle
        circle_3 = Circle().scale(2).next_to(b, DR, buff=0)
        r = circle_3.get_width() / 2
        circle_4 = Circle().set_width(10 - circle_3.get_width()).next_to(d, UL, buff=0)
        self.add(circle_3, circle_4)
        # line
        p = np.array([4 * r / 5, -3 * r / 5, 0]) + circle_3.get_center()
        e = p + np.array([0, 6 * r / 5, 0])
        f = e + np.array([0, -6, 0])
        o1, o2 = circle_3.get_center(), circle_4.get_center()
        m, n = (e + p) / 2, (f + p) / 2
        line_x, line_y = Line(o1, o1 + LEFT * r), Line(o2, o2 + RIGHT * (5 - r)),
        self.add(line_x, line_y,
                 Tex('P').next_to(p),
                 Tex('x').next_to(line_x, UP),
                 Tex('y').next_to(line_y, UP),
                 Line(o1, o1 + UP * r),
                 Line(o2, o2 + DOWN * (5 - r)),
                 Line(o1, o2),
                 Line(o1, o1 + DOWN * 3),
                 Line(o2, o2 + LEFT * 4),
                 )
        # animate
        self.wait()


class p4(Scene):
    def construct(self):
        self.camera.frame.scale(1.2)
        width = 9
        height = 8
        b, c, d, a = [-width / 2, height / 2, 0], [width / 2, height / 2, 0], [width / 2, -height / 2, 0], [-width / 2,
                                                                                                            -height / 2,
                                                                                                            0]
        abcd = Polygon(a, b, c, d)
        b8 = Brace(abcd, LEFT).set_color(BLACK)
        self.add(b8, abcd,
                 Tex('A').next_to(a, DL),
                 Tex('B').next_to(b, UL),
                 Tex('C').next_to(c, UR),
                 Tex('D').next_to(d, DR),
                 Tex('8').next_to(b8, LEFT)
                 )
        # circle
        r = ValueTracker(0.5)
        circle_3 = Circle().add_updater(lambda m: m.become(
            Circle(radius=r.get_value()).scale(2).next_to(b, DR, buff=0)
        ))
        circle_4 = Circle(radius=5 - r.get_value()).add_updater(lambda m: m.become(
            Circle().set_width(10 - circle_3.get_width()).next_to(d, UL, buff=0)
        ))
        self.add(circle_3, circle_4)
        # line
        l3 = Line().add_updater(lambda m: m.become(
            Line(circle_3.get_center(), circle_3.get_center() + DOWN * 3)
        ))
        lx_UP = Line().add_updater(lambda m: m.become(
            Line(circle_3.get_center(), circle_3.get_top())
        ))
        lx_LE = Line().add_updater(lambda m: m.become(
            Line(circle_3.get_center(), circle_3.get_left())
        ))
        l4 = Line().add_updater(lambda m: m.become(
            Line(circle_4.get_center(), circle_4.get_center() + LEFT * 4)
        ))
        ly_DO = Line().add_updater(lambda m: m.become(
            Line(circle_4.get_center(), circle_4.get_bottom())
        ))
        ly_RI = Line().add_updater(lambda m: m.become(
            Line(circle_4.get_center(), circle_4.get_right())
        ))
        lxy = Line().add_updater(lambda m: m.become(
            Line(circle_3.get_center(), circle_4.get_center())
        ))
        self.add(l3, l4, lx_LE, lx_UP, ly_DO, ly_RI, lxy,
                 always(Tex('x').next_to, lx_LE, UP),
                 always(Tex('y').next_to, ly_RI, UP),
                 always(Tex('x').next_to, lx_UP),
                 always(Tex('y').next_to, ly_DO),
                 always(Tex('3').next_to, l3, LEFT),
                 always(Tex('4').next_to, l4, DOWN),
                 )
        # animate
        self.play(r.animate.set_value(2))
        self.play(r.animate.set_value(1))
        self.wait()
